﻿<phone:PhoneApplicationPage
    x:Class="SmarterCharger.App.Views.EditSettingsPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:converters="clr-namespace:SmarterCharger.App.Converters"
    mc:Ignorable="d"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,12">
            <Image Source="../Assets/Logo.png" Height="159" Margin="12, 0, 0, 24" HorizontalAlignment="Left" />
            <TextBlock Text="Change settings" Style="{StaticResource PhoneTextTitle2Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
            </Grid.RowDefinitions>
            
            <ProgressBar IsIndeterminate="True" Visibility="{Binding IsLoading, Converter={StaticResource BooleanToVisibilityConverter}}"></ProgressBar>

            <ScrollViewer x:Name="scroller" Grid.Row="1" Template="{StaticResource ScrollViewerWithIndication}">
                <StackPanel>
                    
                    <StackPanel x:Name="PlugPanel" Margin="0,0,0,42">
                        <toolkit:ListPicker x:Name="Plugs" 
                                                ItemsSource="{Binding SmartPlugs}"
                                                IsEnabled="{Binding IsCredentialsValid}" 
                                                SelectedItem="{Binding SelectedSmartPlug, Mode=TwoWay}"
                                                Header="{Binding Path=LocalizedResources.Label_ChoosePlug, Source={StaticResource LocalizedStrings}}" 
                                                DisplayMemberPath="Name"
                                                SelectionMode="Single" ExpansionMode="FullScreenOnly" 
                                                FullModeHeader="{Binding Path=LocalizedResources.Label_ChoosePlug, Source={StaticResource LocalizedStrings}}">
                            <toolkit:ListPicker.FullModeItemTemplate>
                                <DataTemplate>
                                    <StackPanel Margin="0, 12">
                                        <TextBlock Text="{Binding Name}"
                                                       Style="{StaticResource PhoneTextLargeStyle}"></TextBlock>
                                        <TextBlock Text="{Binding SerialNumber}" Style="{StaticResource PhoneTextSubtleStyle}"></TextBlock>
                                    </StackPanel>
                                </DataTemplate>
                            </toolkit:ListPicker.FullModeItemTemplate>
                        </toolkit:ListPicker>
                    </StackPanel>
                    
                    <StackPanel x:Name="ChargeLimitPanel">
                        <TextBlock Text="{Binding Path=LocalizedResources.Label_ChargeLimit, Source={StaticResource LocalizedStrings}}" TextWrapping="Wrap" Style="{StaticResource PhoneTextSubtleStyle}" />
                        <Grid Margin="0,0,0,12">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <StackPanel>
                                <StackPanel Orientation="Horizontal" Margin="0,0,0,24">
                                    <TextBlock Margin="12,0,0,0" Text="{Binding ChargeLimit, Mode=TwoWay}" Style="{StaticResource PhoneTextExtraLargeStyle}" />
                                    <TextBlock Margin="0" Style="{StaticResource PhoneTextExtraLargeStyle}">%</TextBlock>
                                </StackPanel>
                                
                                <TextBlock Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="Wrap">
                                For best battery life, you should charge your battery to 80%
                                </TextBlock>
                            </StackPanel>

                            <StackPanel Grid.Column="1">
                                <Button Command="{Binding AddChargeLimitCommand}" CommandParameter="{Binding}">+</Button>
                                <Button Command="{Binding SubtractChargeLimitCommand}" CommandParameter="{Binding}">-</Button>
                            </StackPanel>
                        </Grid>
                    </StackPanel>
                </StackPanel>
            </ScrollViewer>
        </Grid>
    </Grid>
</phone:PhoneApplicationPage>